module Singly
  class Proxy
    attr_reader :access_token

    def initialize(access_token)
      @access_token = access_token
    end

    def thirtysevensignals(http_method, path, params={})
      proxy("37signals", http_method, path, params)
    end

    def bodymedia(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def dropbox(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def dwolla(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def facebook(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def fitbit(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def flickr(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def foursquare(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def gcal(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def gcontacts(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def gdocs(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def github(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def gmail(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def google(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def gplus(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def imgur(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def instagram(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def klout(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def linkedin(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def meetup(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def paypal(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def picasa(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def rdio(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def reddit(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def runkeeper(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def shutterfly(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def soundcloud(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def stocktwits(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def tout(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def tumblr(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def twitter(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def withings(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def wordpress(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def yammer(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def youtube(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    def zeo(http_method, path, params={})
      proxy(__method__, http_method, path, params)
    end

    private

    def proxy(service, http_method, path, params={})
      params = params.merge(service: service, path: path, access_token: access_token)
      case http_method.to_s.upcase
      when "POST"
        Singly::Proxy::Post.new(params)
      when "PUT"
        Singly::Proxy::Put.new(params)
      when "DELETE"
        Singly::Proxy::Delete.new(params)
      else
        Singly::Proxy::Get.new(params)
      end
    end
  end
end